package com.kevin.controller;


import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.kevin.session.SqlSession;
import com.kevin.session.SqlSessionFactory;
import com.kevin.table.MDataTable;

@Controller  
@RequestMapping("/user")
@ResponseBody
public class UserController {
	private static Logger log=LoggerFactory.getLogger(UserController.class);
	
	@Resource(name="sqlSessionFactory")
	private SqlSessionFactory sqlSessionFactory;
	

	@RequestMapping(value="/test",method=RequestMethod.GET)  
	@Transactional(rollbackFor = Exception.class)
	public Map test(HttpServletRequest request,Model model) throws Exception{  
//		System.out.println(sqlSessionFactory);
		SqlSession session = sqlSessionFactory.openSession("knuser");
//    	MDataTable cc = session.select(2, 2);
		
		MDataTable table = session.newDataTable();
    	table.createRow(true).set("NAME", "GGGG").set("ORDERID", 2);
		table.createRow(true).set("NAME", "HHHG").set("ORDERID", 2);
    	
    	int rlt = session.insert(table);

    	//int i = 1/0;

//    	int userId = Integer.parseInt(request.getParameter("id"));  
//        System.out.println("userId:"+userId);
//        User user=null;
//        if (userId==1) {
//             user = new User();  
//             user.setAge(11);
//             user.setId(1);
//             user.setPassword("123");
//             user.setUserName("javen");
//        }
//       
//        
//        
//        log.debug(user.toString());
//        model.addAttribute("user", user);  
        return table.toMap();  
    }  
}
